import showMsg from '../utils/errmsg'
import { httpHeader } from './../utils/http'
export const state = () => {
    return {
    }
}
const httpObject = {
    transformRequest: [(params) => {
        let result = ''
        Object.keys(params).forEach((key) => {
          if (!Object.is(params[key], undefined) && !Object.is(params[key], null)) {
            result += encodeURIComponent(key) + '=' + encodeURIComponent(params[key]) + '&'
          }
        })
        return result
    }],
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
}
export const mutations = {
}

export const getters = {
}

export const actions = {
    // 注册
    async userRegists({ commit, dispatch }, payload) {        try {
            const response = await this.$axios.$post('/api/regists', payload, httpHeader)
            response.status = response.code === 200
            if (!response.status) showMsg(response.msg, response.code, dispatch)
            return response
        } catch (err) {
            err.status = false
            return err
        }
    },
    // 获取权限列表数据
    async getRoleList({ commit, dispatch }, payload) {
        try {
            const response = await this.$axios.$get('/api/role/open/getRole', payload, httpHeader)
            response.status = response.code === 200
            if (!response.status) showMsg(response.msg, response.code, dispatch)
            return response
        } catch (err) {
            err.status = false
            return err
        }
    },
    // 生成验证码
    async userGifCode({ commit, dispatch }, payload) {
        try {
            const response = await this.$axios.$get('/api/gifCode', payload, httpHeader)
            response.status = response.code === 200
            if (!response.status) showMsg(response.msg, response.code, dispatch)
            return response
        } catch (err) {
            err.status = false
            return err
        }
    },


}
